package com.sip.stream.utils.zfy;

import android.os.Build;
import androidx.exifinterface.media.ExifInterface;

import com.sip.stream.utils.zfy.status.ZFYStatus;

import java.text.SimpleDateFormat;
import java.util.Date;

public class ZFYExifInterTool {
    private static final SimpleDateFormat DateFORMAT = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");

    public static void writeImageExif(String str) {
        try {
            ExifInterface exifInterface = new ExifInterface(str);
            writeCommomExif(exifInterface);
            exifInterface.saveAttributes();
        } catch (Exception unused) {
        }
    }

    public static void writeImageExif(String str, int i) {
        try {
            ExifInterface exifInterface = new ExifInterface(str);
            writeCommomExif(exifInterface);
            exifInterface.setAttribute(ExifInterface.TAG_ORIENTATION, "" + i);
            exifInterface.saveAttributes();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void writeCommomExif(ExifInterface exifInterface) {
        exifInterface.setAttribute(ExifInterface.TAG_MODEL, Build.MODEL);
        SimpleDateFormat simpleDateFormat = DateFORMAT;
        exifInterface.setAttribute(ExifInterface.TAG_DATETIME, simpleDateFormat.format(new Date()));
        exifInterface.setAttribute(ExifInterface.TAG_DATETIME_ORIGINAL, simpleDateFormat.format(new Date()));
        exifInterface.setAttribute(ExifInterface.TAG_ARTIST, ZFYUserInfo.defaultUserInfo().getUserCode());
        exifInterface.setAttribute(ExifInterface.TAG_MAKE, "WX: 7087213");
        if (ZFYStatus.getInstance().getLatitude() > 0.0d) {
            exifInterface.setAttribute(ExifInterface.TAG_GPS_LATITUDE, dec2DMS(ZFYStatus.getInstance().getLatitude()));
            exifInterface.setAttribute(ExifInterface.TAG_GPS_DEST_LATITUDE_REF, ZFYStatus.getInstance().getLocation().getLatitudeStr());
        }
        if (ZFYStatus.getInstance().getLongitude() > 0.0d) {
            exifInterface.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, dec2DMS(ZFYStatus.getInstance().getLongitude()));
            exifInterface.setAttribute(ExifInterface.TAG_GPS_DEST_LONGITUDE_REF, ZFYStatus.getInstance().getLocation().getLongitudeStr());
        }
        exifInterface.setAttribute(ExifInterface.TAG_SOFTWARE, "launcher");
    }

    private static String dec2DMS(double d) {
        if (d <= 0.0d) {
            d = -d;
        }
        String str = Integer.toString((int) d) + "/1,";
        double d2 = (d % 1.0d) * 60.0d;
        return (str + Integer.toString((int) d2) + "/1,") + Integer.toString((int) ((d2 % 1.0d) * 60000.0d)) + "/1000";
    }
}
